﻿Imports System.Drawing

Public Class ControlSurface
  Private _scenes As New List(Of ControlScene)
  Private _index As Integer = 0
  Private _currentSceneIndex As Integer = -1

  Public ReadOnly Property Scenes() As List(Of ControlScene)
    Get
      Return Me._scenes
    End Get
  End Property

  Public ReadOnly Property CurrentScene() As ControlScene
    Get
      If Me._currentSceneIndex >= 0 AndAlso Me._scenes.Count > 0 Then
        Try
          Return Me._scenes(Me._currentSceneIndex)
        Catch ex As IndexOutOfRangeException
        End Try
      End If
      Return Nothing
    End Get
  End Property

  Public Property CurrentSceneIndex() As Integer
    Get
      Return Me._currentSceneIndex
    End Get
    Set(ByVal value As Integer)
      If value >= 0 AndAlso value < Me._scenes.Count Then
        Me._currentSceneIndex = value
      Else
        Me._currentSceneIndex = -1
      End If
    End Set
  End Property

  Public Property Index() As Integer
    Get
      Return Me._index
    End Get
    Set(ByVal value As Integer)
      Me._index = value
    End Set
  End Property

  Public Sub DrawSurface(ByVal g As Graphics, ByVal rect As Rectangle, ByVal dpiFactor As Single, Optional ByVal drawRowOutline As Boolean = False, Optional ByVal drawButtonOutline As Boolean = False)
    If Me._scenes.Count > 0 AndAlso Me._currentSceneIndex >= 0 AndAlso Me._currentSceneIndex < Me._scenes.Count Then
      Me._scenes(Me._currentSceneIndex).DrawScene(g, rect, dpiFactor, drawRowOutline, drawButtonOutline)
    End If
  End Sub

  Public Sub Clear()
    For Each s As ControlScene In Me._scenes
      s.Clear()
    Next
    Me._scenes.Clear()
    Me._index = 0
    Me._currentSceneIndex = -1
  End Sub

  ''' <summary>
  ''' Returns a deep copy of this object.  The returned object will be logically identical to the source object, but will share no references.
  ''' </summary>
  Public Function Copy() As ControlSurface
    Dim sc As New ControlSurface
    For Each s As ControlScene In Me._scenes
      sc.Scenes.Add(s.Copy)
    Next
    Return sc
  End Function
End Class
